<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class Sensitiveword implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function  getSensitive()
    {
        $arr = [];
        foreach (\App\Sensitiveword::all() as $word) {
            array_push($arr, $word->word);
        }
        return $arr;
    }
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */

    public function passes($attribute, $value)
    {
       $arr = $this->getSensitive();
       foreach ($arr as $word) {
        if (strripos($value, $word) !== false) {
            return false;
        }
    }
    return true;
    }
    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '含有敏感词汇，请重新输入!';
    }
}
